#include<bits/stdc++.h>
#define ll long long
using namespace std;

int T;
int n;
int a[100005];
bool c[100005];
int ans;

void dfs(int dep, int sum) {
    if(dep == n+1) {
        ans = max(ans, sum);
        return ;
    }
    int sum1 = sum;
    c[dep] = 0;
    for(int i = dep-1; i >= 1; i--) {
        if(c[i] == c[dep]) {
            if(a[i] == a[dep]) sum += a[i];
            break;
        }
    }
    dfs(dep+1, sum);
    c[dep] = 1;
    for(int i = dep-1; i >= 1; i--) {
        if(c[i] == c[dep]) {
            if(a[i] == a[dep]) sum1 += a[i];
            break;
        }
    }
    dfs(dep+1, sum1);
}


int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    scanf("%d", &T);
    while(T--) {
        ans = 0;
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
        }
        dfs(1, 0);
        printf("%d\n", ans);
    }

    return 0;
}
